package com.cnt.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cnt.entity.User;
import com.cnt.vo.UserResultVo.queryUserResultVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao extends BaseMapper<User> {

    @Select("select user_id, account, password, name, id_card, user_role, login_fail_times from user where account= #{account}")
    public User findByAccount(String account);

    @Update("UPDATE user SET login_fail_times = login_fail_times + 1 WHERE user_id = #{sid}")
    public int incrementLoginFailTimes(int sid);

    @Update("UPDATE user SET login_fail_times = 0 WHERE user_id = #{sid}")
    public int resetLoginFailTimes(int sid);

//    @Select("SELECT u.user_id, u.name, u.account, u.user_role, u.login_fail_times, info.age, info.phone, info.charitable_score " +
//            "FROM USER u " +
//            "INNER JOIN user_info info ON u.user_id = info.user_id " +
//            "WHERE 1=1 " +
//            "AND (u.account LIKE CONCAT('%', #{account}, '%') OR #{account} IS NULL OR #{account} = '') " +
//            "AND (info.phone LIKE CONCAT('%', #{phone}, '%') OR #{phone} IS NULL OR #{phone} = '') " +
//            "AND (( " +
//            "   #{queryType} = 0 AND u.user_role = 0) OR " +
//            "   (#{queryType} = 1 AND u.user_role > 0) OR " +
//            "   #{queryType} IS NULL " +
//            ") " +
//            "AND (( " +
//            "   #{queryStatus} = 1 AND u.login_fail_times > 7) OR " +
//            "   #{queryStatus} IS NULL " +
//            ") "+
//            "ORDER BY " +
//            "   CASE #{querySort} " +
//            "       WHEN 0 THEN u.user_id ASC " +
//            "       WHEN 1 THEN u.user_id DESC " +
//            "       WHEN 2 THEN info.charitable_score ASC " +
//            "       ELSE info.charitable_score DESC " +
//            "   END,  " +
//            "   u.user_id DESC;"
//            )
    List<queryUserResultVo> queryUser(String account, String phone, Integer queryType, Integer queryStatus, Integer querySort);


}
